package org.linlinjava.litemall.core.payment.clover.config;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.paypal.base.rest.APIContext;
import com.paypal.base.rest.PayPalRESTException;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.linlinjava.litemall.db.domain.LumiereCloverCode;
import org.linlinjava.litemall.db.service.LumiereCloverCodeService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.time.LocalDateTime;
import java.util.List;
import java.util.TimeZone;


/**
 * 初始化商家令牌
 * @author ：stephen
 * @date ：Created in 11/19/2019 2:08 PM
 * @description：TODO
 */

@Configuration
@Data
@Slf4j
@RequiredArgsConstructor
public class CloverConfig {
    private String merchantId;
    private String employeeId;
    private String clientId;
    private String code;
    private String clientSecret;
    private String accessToken;

    private final LumiereCloverCodeService lumiereCloverCodeService;

    @PostConstruct
    private void init() {
        //获取最新的商家令牌(令牌有效期一年)
        List<LumiereCloverCode> cloverCodeList = lumiereCloverCodeService.list(Wrappers.lambdaQuery(LumiereCloverCode.class)
                .orderByAsc(LumiereCloverCode::getAddTime));
        LumiereCloverCode cloverCode = cloverCodeList.get(cloverCodeList.size()-1);
        merchantId=cloverCode.getMerchantId();
        employeeId=cloverCode.getEmployeeId();
        clientId=cloverCode.getClientId();
        code=cloverCode.getCode();
        clientSecret=cloverCode.getClientId();
        accessToken=cloverCode.getAccessToken();
        log.info("初始化令牌->{}",accessToken);
    }


}
